def count_sort(arr):
    out = [0] * len(arr)
    count = [0] * (max(arr) + 1)
    for i in arr:
        count[i] += 1
    for i in range(1, len(count)):
        count[i] += count[i-1]
    for i in range(len(arr)-1, -1, -1):
        count[arr[i]] -= 1
        out[count[arr[i]]] = arr[i]
    return out

print(count_sort([1, 2, 2, 6, 4, 5]))
